/**
 * 截取输入框中粘贴赋值进来的换行符
 */
import { debounce } from 'lodash'
export default {
  name: 'sliceWrap',
  bind (el: any) {
    const newEl = el.tagName === 'TEXTAREA' ? el : el.querySelector('TEXTAREA')
    function listenerFn () {
      if (newEl.value) {
        const reg = /(\r|\n|\r\n)/gi
        newEl.value = newEl.value.replace(reg, '')
      }
    }
    newEl.removeEventListener('input', debounce(listenerFn, 50), true)
    newEl.addEventListener('input', debounce(listenerFn, 50), true)
  }
}
